<cfcomponent extends="assets.calgrants.com.Base">

	<cfscript>
        import assets.calgrants.com.bo.Site;
	</cfscript>
	
	<cffunction name="get" access="public" output="false" returntype="assets.calgrants.com.bo.Site">
		<cfargument name="Site_ID" type="numeric" required="true" />
		<cfscript>
			if (arguments.Site_ID gt 0) {
				local.loadArgs = {};
				local.loadArgs.obj = new Site();
				StructAppend(local.loadArgs, QueryToStruct(read(argumentCollection = arguments))[1]);
				return load(argumentCollection = local.loadArgs);
			} else {
				return new Site();
			}
		</cfscript>
	</cffunction>
	
	<cffunction name="load" access="public" output="false" returntype="assets.calgrants.com.bo.Site">
		<cfargument name="obj" type="assets.calgrants.com.bo.Site" required="true" />
		<cfscript>
			local.obj = arguments.obj;
			if (IsDefined("arguments.Site_ID")) {
				local.obj.setSite_ID(arguments.Site_ID);
			}
			if (IsDefined("arguments.Deleted")) {
				local.obj.setDeleted(arguments.Deleted);
			}
			if (IsDefined("arguments.Organization_ID")) {
				local.obj.setOrganization_ID(arguments.Organization_ID);
			}
			if (IsDefined("arguments.Site")) {
				local.obj.setSite(arguments.Site); 
			}
			if (IsDefined("arguments.Site_Type")) {
				local.obj.setSite_Type(arguments.Site_Type); 
			}
			if (IsDefined("arguments.Address")) {                             
				local.obj.setAddress(arguments.Address);
			}
			if (IsDefined("arguments.City")) {
				local.obj.setCity(arguments.City);
			}
			if (IsDefined("arguments.Zip_Code")) {
				local.obj.setZip_Code(arguments.Zip_Code);
			}
			if (IsDefined("arguments.County_ID")) {
				local.obj.setCounty_ID(arguments.County_ID);
			}
			if (IsDefined("arguments.Computers")) {
				local.obj.setComputers(arguments.Computers);
			}
			if (IsDefined("arguments.Date_Created")) {
				local.obj.setDate_Created(arguments.Date_Created);
			}
			return local.obj;
		</cfscript>
	</cffunction>

	<cffunction name="read" access="public" output="false" returntype="any">
		<cfargument name="Site_ID" required="false" default="" />
		<cfargument name="Deleted" required="false" default="0" />
		<cfargument name="Organization_ID" required="false" default="" />
		<cfargument name="Site" required="false" default="" />
		<cfargument name="Site_Type" required="false" default="" />
		<cfargument name="Address" required="false" default="" />
		<cfargument name="City" required="false" default="" />
		<cfargument name="Zip_Code" required="false" default="" />
		<cfargument name="County_ID" required="false" default="" />
		<cfargument name="Computers" required="false" default="" />
		<cfargument name="Date_Created" required="false" default="" />

		<cfset var recs = "">
		<cfstoredproc datasource="#getDatasource()#" procedure="readSite">
			<cfprocparam value="#arguments.Site_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Site_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Deleted#" cfsqltype="CF_SQL_BIT" null="#IIf(Len(Trim(arguments.Deleted)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Organization_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.Organization_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Site#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Site)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Site_Type#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Site_Type)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Address#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Address)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.City#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.City)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Zip_Code#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Zip_Code)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.County_ID#" cfsqltype="CF_SQL_INTEGER" null="#IIf(Len(Trim(arguments.County_ID)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Computers#" cfsqltype="CF_SQL_VARCHAR" null="#IIf(Len(Trim(arguments.Computers)) eq 0, true, false)#" />
			<cfprocparam value="#arguments.Date_Created#" cfsqltype="CF_SQL_TIMESTAMP" null="#IIf(Len(Trim(arguments.Date_Created)) eq 0, true, false)#" />
			<cfprocresult name="recs" />
		</cfstoredproc>
		<cfreturn recs />
	</cffunction>

	<cffunction name="save" access="public" output="false" returntype="any">
		<cfargument name="site" required="true" type="assets.calgrants.com.bo.Site" />

		<cfstoredproc datasource="#getDatasource()#" procedure="saveSite">
			<cfprocparam value="#site.getSite_ID()#" cfsqltype="CF_SQL_INTEGER" variable="id" type="inout" null="false" />
			<cfprocparam value="#site.getDeleted()#" cfsqltype="CF_SQL_BIT" null="false" />
			<cfprocparam value="#site.getOrganization_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#site.getSite()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#site.getSite_Type()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#site.getAddress()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#site.getCity()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#site.getZip_Code()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
			<cfprocparam value="#site.getCounty_ID()#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="#site.getComputers()#" cfsqltype="CF_SQL_VARCHAR" null="false" />
		</cfstoredproc>
		<cfreturn id />
	</cffunction>

	<cffunction name="destroy" access="public" output="false" returntype="any">
		<cfargument name="Site_ID" required="true" />

		<cfstoredproc datasource="#getDatasource()#" procedure="destroySite">
			<cfprocparam value="#arguments.Site_ID#" cfsqltype="CF_SQL_INTEGER" null="false" />
			<cfprocparam value="true" cfsqltype="CF_SQL_BIT" null="false" />
		</cfstoredproc>
		<cfreturn true />
	</cffunction>

</cfcomponent>

